package string;

public class StringBuilderDemo {
    public static void main(String[] args) {
        // StringBuilder的创建方式
        /*
        StringBuilder builder1=new StringBuilder();
        StringBuilder builder2=new StringBuilder("abc");
        //
        String str="abc";
        StringBuilder builder3=new StringBuilder(str);
        String str2=builder3.toString();
        System.out.println(builder3);
        System.out.println(str2);
         */

        //基于字符串创建StringBuilder对象
        //可以改变
        //append()方法,在尾部添加内容
        String str="好好学习Java";
        StringBuilder builder=new StringBuilder(str);
        builder.append(",为了学好Java");
        System.out.println(builder);
        //replace()方法,替换指定位置的内容
        //要头不要尾
        builder.replace(9,19,"为了改变世界");
        System.out.println(builder);

        //delete()方法,删除指定位置的内容
        builder.delete(0,8);
        System.out.println(builder);
        //insert()方法，在指定位置插入内容
        builder.insert(0,"活着");
        System.out.println(builder);
        //reverse()方法，反转字符串
        builder.reverse();
        System.out.println(builder);

    }
}
